package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.itcast.crm.domain.Customer;

public interface CustomerRepository extends JpaRepository<Customer, Integer> {
	public List<Customer> findByFixedAreaIdIsNull();

	public List<Customer> findByFixedAreaId(String customerFixedAreaId);

	@Query(value = "update Customer set fixedAreaId = ?1 where id = ?2")
	@Modifying
	public void updateAssocaition(String customerFixedAreaId, Integer customerId);

	@Query(value = "update Customer set fixedAreaId = null where fixedAreaId = ?1")
	@Modifying
	public void clearAssocaition(String customerFixedAreaId);

	public Customer findByTelephone(String telephone);

	@Query(value = "update Customer set type = 1 where telephone = ?1")
	@Modifying
	public void updateType(String telephone);

	public Customer findByTelephoneAndPassword(String telephone, String password);

	@Query(value = "select fixedAreaId from Customer where address = ?1")
	public String findFixedAreaIdByAddress(String address);

}
